3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
The clearest way to understand the metafile format for polyhedra is to begin with the polyhedron data structures in the QD3D file QD3DGeometry.h:
typedef enum TQ3PolyhedronEdgeMasks {
kQ3PolyhedronEdgeNone = 0,
kQ3PolyhedronEdge01 = 1 << 0,
kQ3PolyhedronEdge12 = 1 << 1,
kQ3PolyhedronEdge20 = 1 << 2,
kQ3PolyhedronEdgeAll = kQ3PolyhedronEdge01 |
kQ3PolyhedronEdge12 |
kQ3PolyhedronEdge20
} TQ3PolyhedronEdgeMasks;
typedef unsigned long TQ3PolyhedronEdge;
typedef struct TQ3PolyhedronEdgeData {
unsigned long vertexIndices[2];
unsigned long triangleIndices[2];
TQ3AttributeSet edgeAttributeSet;
} TQ3PolyhedronEdgeData;
typedef struct TQ3PolyhedronTriangleData {
unsigned long vertexIndices[3];
TQ3PolyhedronEdge edgeFlag;
TQ3AttributeSet triangleAttributeSet;
} TQ3PolyhedronTriangleData;
typedef struct TQ3PolyhedronData {
unsigned long numVertices;
TQ3Vertex3D *vertices;
unsigned long numEdges;
TQ3PolyhedronEdgeData *edges;
unsigned long numTriangles;
TQ3PolyhedronTriangleData *triangles;
TQ3AttributeSet polyhedronAttributeSet;
} TQ3PolyhedronData;
The polyhedron metafile object makes use of the following auxiliary data structures. These differ from the above data structures in that all attributeSet fields have been removed. Instead, the attributeSet fields are collected in AttributeSetList subobjects, which are discussed in "Attribute Set Lists" .
typedef enum PolyhedronEdge {
PolyhedronEdgeNone = 0,
PolyhedronEdge01 = 1 << 0,
PolyhedronEdge12 = 1 << 1,
PolyhedronEdge20 = 1 << 2,
PolyhedronEdgeAll = PolyhedronEdge01 |
PolyhedronEdge12|
PolyhedronEdge20
} PolyhedronEdge;
typedef struct PolyhedronEdgeData {
unsigned long vertexIndices[2];
unsigned long triangleIndices[2];
} PolyhedronEdgeData;
typedef struct PolyhedronTriangleData {
unsigned long vertexIndices[3];
PolyhedronEdge edgeFlag;
} PolyhedronTriangleData;
Given these, the metafile format of the polyhedron object itself is:
Uns32 numVertices
Uns32 numEdges
Uns32 numTriangles
Point3D vertices[numVertices]
PolyhedronEdgeData edges[numEdges]
PolyhedronTriangleData triangles[numTriangles]
numVertices The number of vertices.
A polyhedron is composed of triangular faces. The basic idea is to have a list of points (the vertices), and then organize those points into a set of triangular faces. The triangles are specified by indices into the array of points. Since typically a single point is a vertex of 3 or more triangles, referencing the points by index saves space. (For further details on the polyhedron geometry, see 3D Graphics Programming With QuickDraw 3D 1.5. Also, see develop magazine by Apple Computer, Issue 28, Dec. 1996, "New QuickDraw 3D Geometries," p. 32.)
In addition to the data in its root object, a polyhedron object can have as many as four subobjects: A VertexAttributeSetList for the attributeSet s in the array of TQ3Vertex3D ; a GeometryAttributeSetList for the attributeSet s in the array of TQ3PolyhedronEdgeData ; and a FaceAttributeSetList for the attributeSets in the array of TQ3PolyhedronTriangleData ; and the usual geometry AttributeSet . See the appropriate sections of this document for descriptions of their formats.
The following example represents a complete metafile written by QD3D 1.5. For information about attribute arrays, see "Attribute Arrays" .
3DMetafile ( 1 5 Normal tableofcontents0> )
polyhedron2:
Container (
Polyhedron (
6 0 4 # numVertices
# numEdges
# numTriangles
-20 -20 0 -20 10 0 0 0 0 0 30 0 20 -20 0 20 10 0
0 3 1 Edge01 | Edge12 | Edge20
0 2 3 Edge01 | Edge12 | Edge20
2 4 3 Edge01 | Edge12 | Edge20
4 5 3 Edge01 | Edge12 | Edge20
)
Container (
VertexAttributeSetList ( 6 Exclude 0 )
attributeset3:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 1 1 )
)
attributeset4:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.95 1 )
)
attributeset5:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.9 1 )
)
attributeset6:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.85 1 )
)
attributeset7:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.8 1 )
)
attributeset8:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.75 1 )
)
)
Container (
FaceAttributeSetList ( 4 Exclude 0 )
attributeset9:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.7 1 )
)
attributeset10:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.65 1 )
)
attributeset11:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.6 1 )
)
attributeset12:
Container (
AttributeSet ( )
AmbientCoefficient ( 1 )
DiffuseColor ( 0 0.55 1 )
)
)
attributeset13:
Container (
AttributeSet ( )
AmbientCoefficient ( 0.5 )
DiffuseColor ( 1 0 0 )
)
)
Previous | QD3D Book | Overview | Chapter Contents | Next |